package com.kabuda.hot100.二叉树.easy;

import com.kabuda.hot100.二叉树.TreeNode;

/**
 * @author kabuda
 * @date 2025-03-08 17:18
 * @description 给你一个二叉树的根节点 root ， 检查它是否轴对称。
 */
public class t101_对齐二叉树 {
    public static void main(String[] args) {
        TreeNode treeNode1 = new TreeNode(3);
        TreeNode treeNode2 = new TreeNode(9);
        TreeNode treeNode3 = new TreeNode(20);
        TreeNode treeNode4 = new TreeNode(15);
        TreeNode treeNode5 = new TreeNode(7);
        treeNode1.left = treeNode2;
        treeNode1.right = treeNode3;
        treeNode3.left = treeNode4;
        treeNode3.right = treeNode5;

        System.out.println(isSymmetric(treeNode1));
    }

    public static boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return true;
        }
        return recursion(root.left, root.right);
    }

    public static boolean recursion(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        }

        if (left == null || right == null || left.val != right.val) {
            return false;
        }

        return recursion(left.left, right.right)&& recursion(left.right, right.left);

    }


}
